-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bring in scroll damper #49
Conversation
Fix issue with null velocity_helper
Thank you very much for your work on this pull request and its documentation! These are quite nice changes that will enhance the addon a lot. There are some things I would suggest or would like to hear your opinion on:
Generally, I'd also like to conform with the official GDScript styling guidelines for Godot 4. |
I 'm really not good at naming, but I've tried some new changes.
I do have thought about this before. However, they are true parameters that formulas use. I 'm worrying about modifying factors might cause maintenance difficulties in the future. |
What do you think of the names |
Actually, before I brought these classes to this project, they were generic utility classes that helped me simplify formula calculations, which led me to be conservative in naming. Then I realized that since this is now utilities only for this project, I thought we could make the naming a little more specific. |
Yeah, ScrollDamper is a good name. Do you have anything you want to add or can you spot something I missed out on? Otherwise, I would merge this and create a new 1.3 release. |
I 've made some changes to narrow the range of parameters of scroll damper in the latest commit. See if it is you want.
I guess it's all well and done. |
I just noticed some stuttering on really slow movement, but that existed before already so I will create a new issue for that. What is SmoothScrollContainer2 for, can it be removed? |
Ahh, my apologies. I added some casual testing changes in that commit. |
Bring.in.VelocityHelper.mp4
VelocityHelper has been renamed as ScrollDamper
Introduce ScrollDamper
I wrote a utility class that helps developers to handle velocity in convenience. ScrollDamper is an abstract class which shouldn't be used directly but to extend. For now, I brought in four different scroll dampers, they are LinearScrollDamper, QuadScrollDamper, CubicScrollDamper and ExpoScrollDamper. The last one is similar to the original way, and it's the default ScrollDamper once SmoothScrollContainer is created in editor.
How to use
slide()
Fill in parameters it needs, it will return the next velocity and relative offset (not position).
attract()
Emulate force that attracts something to destination. Return the result of next velocity according to delta time.
rebound_strength
The higher the value, the faster attract() attracts.
_calculate_velocity_to_dest()
Return the exact velocity that makes something slide to destination.
How to extend
To show how scroll damper works, here we take LinearScrollDamper as example.
In convenience of calculation, we assume that x axis is time, but time comes from infinity to zero.
_calculate_velocity_by_time(time)
For linear velocity, we let velocity slows down as time count down to zero, which is:
_factor
is a private variable of LinearScrollDamper, usingfriction
to set its value indirectly is a simpler way. The greater the value, the faster the velocity decrease.The differential of this formula must greater than 0 no matter what "time" it is, or it might cause some issue.
_calculate_time_by_velocity(velocity)
It's the reverse calculation of the previous formula.
Notice that no matter what sign velocity is, we regard it as positive.
_calculate_offset_by_time(time)
This is the integral for the formula in _calculate_velocity_by_time(time). Constant is not needed.
_calculate_time_by_offset(offset)
It's the reverse calculation of the previous formula.
Notice
Need more testing: A big part of the script has been rewritten, since it is involved deeply.
Incompatible changes: Friction and damping is removed which is not a compatible change.
Other changes
Useful methods
get_spare_size()
Scroll bar takes up some space of the container, which might cause some calculation mistakes. Using get_spare_size() to get spare space size.
get_child_size_diff()
Get the size differences between child node and container. Child node 's scale and scroll bar size are taken into consideration. It could be useful for future development like content scaling.
get_child_boundary_dist()
Get the left, right, top and bottom distance.
Redesigned interface
Since the exposed properties are getting more, it is a good time to reorder these properties.
[Edited]
Tween for scroll_to()
Tween for scroll_to function will fight against scrolling and dragging input when tween animation is not done. Now all the scroll_to tween will be killed if needed.